import { fallbackRequestGet, fallbackRequestPost } from '@/utils/Request'

/**
 * 请求前缀，后面后台添加网关后需要前缀选择微服务
 */
const URL_PREFIX = 'middle-user/'

/**
 * 查询所有身份信息
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryProvinces = (successCallback = null, fullCallback = null) => {
  const params = {}
  return fallbackRequestGet(URL_PREFIX + 'userAddress/queryProvinces', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 根据provinceId查询city信息
 * @param {BigInteger} id provinceId
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryCitiesByProvince = (id, successCallback = null, fullCallback = null) => {
  const params = {
    id
  }
  return fallbackRequestGet(URL_PREFIX + 'userAddress/queryCitiesByProvince', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 根据cityId查询County信息
 * @param {BigInteger} id CityId
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryCountiesByCity = (id, successCallback = null, fullCallback = null) => {
  const params = {
    id
  }
  return fallbackRequestGet(URL_PREFIX + 'userAddress/queryCountiesByCity', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 根据CountyId查询Town信息
 * @param {BigInteger} id CountyId
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryTownsByCounty = (id, successCallback = null, fullCallback = null) => {
  const params = {
    id
  }
  return fallbackRequestGet(URL_PREFIX + 'userAddress/queryTownsByCounty', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 根据townId查询Village信息
 * @param {BigInteger} id townId
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryVillagesByTown = (id, successCallback = null, fullCallback = null) => {
  const params = {
    id
  }
  return fallbackRequestGet(URL_PREFIX + 'userAddress/queryVillagesByTown', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 查询当前登陆用户所有地址信息
 * @param {Number} id 地址id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryAddressById = (id, successCallback = null, fullCallback = null) => {
  const params = {
    id
  }
  return fallbackRequestGet(URL_PREFIX + 'userAddress/queryAddressById', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 查询当前登陆用户所有地址信息
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryAllUserAddress = (successCallback = null, fullCallback = null) => {
  const params = {}
  return fallbackRequestGet(URL_PREFIX + 'userAddress/queryAllUserAddress', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 查询当前登陆用户默认地址信息，返回null表示咩有默认地址
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const queryDefaultUserAddress = (successCallback = null, fullCallback = null) => {
  const params = {}
  return fallbackRequestGet(URL_PREFIX + 'userAddress/queryDefaultUserAddress', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 根据id删除用户的地址信息
 * @param {BigInteger} id 地址信息id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const deleteUserAddressById = (id, successCallback = null, fullCallback = null) => {
  const params = {
    id
  }
  return fallbackRequestGet(URL_PREFIX + 'userAddress/deleteUserAddressById', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 插入新的用户地址信息
 * @param {UserAddressInsertDTO} userAddressInsertDTO 地址信息id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const insertUserAddress = (userAddressInsertDTO, successCallback = null, fullCallback = null) => {
  const params = Object.assign({}, userAddressInsertDTO)
  return fallbackRequestPost(URL_PREFIX + 'userAddress/insertUserAddress', params, {}, true, successCallback, null, fullCallback)
}

/**
 * 根据id修改用户地址信息
 * @param {UserAddressChgDTO} userAddressChgDTO 地址信息id
 * @param {Function} successCallback 成功回调，参数为data
 * @param {Function} fullCallback 肯定触发的回调，先于callback
 */
export const updateUserAddressById = (userAddressChgDTO, successCallback = null, fullCallback = null) => {
  const params = Object.assign({}, userAddressChgDTO)
  return fallbackRequestPost(URL_PREFIX + 'userAddress/updateUserAddressById', params, {}, true, successCallback, null, fullCallback)
}
